package com.ruoyi.system.service.construction.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.construction.ConstructionInfo;
import com.ruoyi.system.domain.construction.WordMark;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.SupplierInfo;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.construction.ConstructionInfoMapper;
import com.ruoyi.system.mapper.construction.WordMarkMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.SupplierInfoMapper;
import com.ruoyi.system.service.construction.WordMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 字体Service业务层处理
 * 
 * @author 张少丛
 * @date 2020-11-04
 */
@Service
public class WordMarkServiceImpl implements WordMarkService
{
    @Autowired
    private WordMarkMapper wordMarkMapper;

    @Autowired
    private ConstructionInfoMapper constructionInfoMapper;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询字体
     * 
     * @param wordId 字体ID
     * @return 字体
     */
    @Override
    public WordMark selectWordMarkById(Integer wordId)
    {
        return wordMarkMapper.selectWordMarkById(wordId);
    }

    /**
     * 查询字体列表
     * 
     * @param wordMark 字体
     * @return 字体
     */
    @Override
    public List<WordMark> selectWordMarkList(WordMark wordMark,Long userId)
    {
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 创建集合储存施工队人员ID
        List<Long> teamInfoIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.selectSupplierInfoByUserId(supplierInfo);
        if(supplierInfoList.size()>0){
            for (SupplierInfo supplier : supplierInfoList) {
                supplierIds.add(Long.valueOf(supplier.getSupplierId()));
            }
        }else{
            supplierIds.add(Long.valueOf(-1));
        }
        // 创建人员实体类
        ConstructionInfo constructionInfo = new ConstructionInfo();
        constructionInfo.setSupplierIds(supplierIds);
        // 根据供应商ID查询所有人员信息
        List<ConstructionInfo> constructionInfoList = this.constructionInfoMapper.selectConstructionInfo(constructionInfo);
        // 添加人员ID到集合中
        if (constructionInfoList.size() > 0) {
            // 添加人员ID到集合中
            for (ConstructionInfo cInfo : constructionInfoList) {
                teamInfoIds.add(cInfo.getConstructionId());
            }
        }else{
            teamInfoIds.add(Long.valueOf(-1));
        }
        wordMark.setConstructionInfoIds(teamInfoIds);
        return wordMarkMapper.selectWordMarkList(wordMark);
    }

    /**
     * 新增字体
     * 
     * @param wordMark 字体
     * @return 结果
     */
    @Override
    public int insertWordMark(WordMark wordMark)
    {
        return wordMarkMapper.insertWordMark(wordMark);
    }

    /**
     * 修改字体
     * 
     * @param wordMark 字体
     * @return 结果
     */
    @Override
    public int updateWordMark(WordMark wordMark)
    {
        return wordMarkMapper.updateWordMark(wordMark);
    }

    /**
     * 批量删除字体
     * 
     * @param wordIds 需要删除的字体ID
     * @return 结果
     */
    @Override
    public int deleteWordMarkByIds(Integer[] wordIds)
    {
        return wordMarkMapper.deleteWordMarkByIds(wordIds);
    }

    /**
     * 删除字体信息
     * 
     * @param wordId 字体ID
     * @return 结果
     */
    @Override
    public int deleteWordMarkById(Integer wordId)
    {
        return wordMarkMapper.deleteWordMarkById(wordId);
    }

    /**
     * 查询施工队信息
     * @return
     */
    public List<ConstructionInfo> selectConstructionInfo(Long userId){
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.selectSupplierInfoByUserId(supplierInfo);
        for (SupplierInfo supplier : supplierInfoList) {
            supplierIds.add(Long.valueOf(supplier.getSupplierId()));
        }
        // 创建人员实体类
        ConstructionInfo constructionInfo = new ConstructionInfo();
        constructionInfo.setSupplierIds(supplierIds);
        // 根据供应商ID查询所有人员信息
        List<ConstructionInfo> constructionInfoList = this.constructionInfoMapper.selectConstructionInfo(constructionInfo);
        return constructionInfoList;
    }
}
